import QtQuick 2.4

ConfirmRulePageForm {
    mouseArea.onClicked: {
        Game.beginGame();
        stackView.replace("qrc:///Pages/QuestionPage.qml")
    }


    backButton.onClicked:{
        Game.endGame();
        stackView.pop();
    }


//    fake1.onClicked: {
//        Game.fakePlayer(0x01, "1234567890")

//    }

//    fake2.onClicked: {
//        Game.fakePlayer(0x01, "1234567891")
//    }

//    fake3.onClicked: {
//        Game.fakePlayer(0x01, "1234567892")
//    }

    Component.onCompleted: {
        itemOk.visible  = false

        Game.beginGame()

        tipText.text  = "1\n号选手请录入手环"
        Game.readBracelet(0x01)
    }

    Connections{
        target: Game
        onPlayerJoin:{
            console.log(player, "通过刷卡参与到游戏")
            if(player === 0x01){
                tipText.text  = "2\n号选手请录入手环"
                Game.readBracelet(0x02)
            }
            else if(player === 0x02){
                if(Game.needNextPlayer()){
                    tipText.text  = "3\n号选手请录入手环"
                    Game.readBracelet(0x04)
                }
                else{

                }
            }
        }

        onAllPlayerReady:{
            console.log("参与人数满足游戏设置");
            tipText.visible  = false
            itemOk.visible  = true
        }

        onPlayerIllegal:{
            console.log(player, "手环无效")
            tipText.text  = "手环无效，请重试"
            Game.readBracelet(player)
        }
    }
}
